package com.atguigu.realtime.util;

import java.text.ParseException;
import java.text.SimpleDateFormat;

/**
 * @Author lizhenchao@atguigu.cn
 * @Date 2021/4/23 10:42
 */
public class MyTimeUtil {
    
    public static Long getTs(String dateTime, String  format) {
        try {
            return new SimpleDateFormat(format).parse(dateTime).getTime();
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return null;
    }
    
    public static Long getTs(String dateTime) {
        return getTs(dateTime, "yyyy-MM-dd HH:mm:ss");
    }
    
    public static String toDateTimeString(long ts) {
        return new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(ts);
    }
}
